/* Table 1 */
tabstat rating_num rating_fee rating_fee_residual issue_amountm revenue go paidprev moodys fitch issue_insured lost_insurance if , stat(n mean sd p25 p50 p75)
tabstat rating_num rating_fee rating_fee_residual issue_amountm revenue go paidprev moodys fitch issue_insured lost_insurance if issue_insured == 1 , stat(n mean sd p25 p50 p75)
tabstat rating_num rating_fee rating_fee_residual issue_amountm revenue go paidprev moodys fitch issue_insured lost_insurance if & issue_insured == 0 , stat(n mean sd p25 p50 p75)
tabstat rating_num rating_fee rating_fee_residual issue_amountm revenue go paidprev moodys fitch issue_insured lost_insurance if issue_insured == 0 & lost_insurance == 0 , stat(n mean sd p25 p50 p75)
tabstat rating_num rating_fee rating_fee_residual issue_amountm revenue go paidprev moodys fitch issue_insured lost_insurance if issue_insured == 0 & lost_insurance == 1 , stat(n mean sd p25 p50 p75)

/* Table 2 Panel A */
reghdfe rating_fee paidprev if issue_insured != . & rating_num != . & moodyspost051007 != . & fitchpost041005 != . , a(issue_amount_bucket#rater_3#year#type_of_debt_3) resid
predict rating_fee_residual , residuals

/* Table 2 Panel B */
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if issue_insured == 0 | issue_insured == 1 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if issue_insured == 1 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if issue_insured == 0 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if issue_insured == 0 & lost_insurance == 0 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if issue_insured == 0 & lost_insurance == 1 , a(issue_fe) cluster(issue_fe)

/* Table 2 Panel C */
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if aaalastyear == 0 & (issue_insured == 0 | issue_insured == 1) , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if aaalastyear == 0 & issue_insured == 1 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if aaalastyear == 0 & issue_insured == 0 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if aaalastyear == 0 & issue_insured == 0 & lost_insurance == 0 , a(issue_fe) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if aaalastyear == 0 & issue_insured == 0 & lost_insurance == 1 , a(issue_fe) cluster(issue_fe)

/* Table 2 Panel D */
reghdfe rating_num sdrating_fee_residual moodys fitch moodyspost051007 issue_insured if moodys == 1 , a(issuer_fe year) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys fitch moodyspost051007 issue_insured if moodys == 1 & aaalastyear == 0 , a(issuer_fe year) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys fitch issue_insured if moodys == 0 & fitch == 0 , a(issuer_fe year) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys fitch issue_insured if moodys == 0 & fitch == 0 & aaalastyear == 0 , a(issuer_fe year) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys fitch fitchpost041005 issue_insured if fitch == 1 , a(issuer_fe year) cluster(issue_fe)
reghdfe rating_num sdrating_fee_residual moodys fitch fitchpost041005 issue_insured if fitch == 1 & aaalastyear == 0 , a(issuer_fe year) cluster(issue_fe)

/* Table 5 */
areg rating_num sdrating_fee_residual paidprev moodys moodyspost051007 if insured == 0 , a(issue_id) cluster(cusip)  
areg rating_num sdrating_fee_residual paidprev moodys moodyspost051007 home_state in_state female advanced_degree agency_tenure10 if insured == 0 , a(issue_id) cluster(cusip)
areg rating_num sdrating_fee_residual scum_cusip paidprev moodys moodyspost051007 home_state in_state female advanced_degree agency_tenure10 if insured == 0 , a(issue_id) cluster(cusip)
areg rating_num sdrating_fee_residual scum_issuer paidprev moodys moodyspost051007 home_state in_state female advanced_degree agency_tenure10 if insured == 0 , a(issue_id) cluster(cusip)
areg rating_num sdrating_fee_residual scum_sector paidprev moodys moodyspost051007 home_state in_state female advanced_degree agency_tenure10 if insured == 0 , a(issue_id) cluster(cusip)

/* Table 6 Panel A */
reg rdelta sdrating_fee_residual   
reg rdelta sdrating_fee_residual if rating_num > 21 
reg rdelta sdrating_fee_residual if rating_num > 18 & rating_num <= 21 
reg rdelta sdrating_fee_residual if rating_num > 15 & rating_num <= 18 

/* Table 6 Panel B */
reg rdelta sdrating_fee_residual   
reg rdelta sdrating_fee_residual if rating_num > 21 
reg rdelta sdrating_fee_residual if rating_num > 18 & rating_num <= 21 
reg rdelta sdrating_fee_residual if rating_num > 15 & rating_num <= 18 

/* Table 7 Panel A and Panel B */
areg spread aaa aau aa aad au a ad aaahighfee aauhighfee aahighfee aadhighfee auhighfee ahighfee adhighfee highfee issue_amount maturity_years n_cumulative coupon revenue negotiated callable if moodys == 1 , a(year) cluster(issuer_name)
test aaahighfee + highfee = 0
test aauhighfee + highfee = 0
test aahighfee + highfee = 0
test aadhighfee + highfee = 0
test auhighfee + highfee = 0
test ahighfee + highfee = 0
test adhighfee + highfee = 0

areg spread aaa aau aa aad au a ad aaahighfee aauhighfee aahighfee aadhighfee auhighfee ahighfee adhighfee highfee issue_amount maturity_years n_cumulative coupon revenue negotiated callable if moodys == 0 & fitch == 0 , a(year) cluster(issuer_name)
test aaahighfee + highfee = 0
test aauhighfee + highfee = 0
test aahighfee + highfee = 0
test aadhighfee + highfee = 0
test auhighfee + highfee = 0
test ahighfee + highfee = 0
test adhighfee + highfee = 0

areg spread aaa aau aa aad au a ad aaahighfee aauhighfee aahighfee aadhighfee auhighfee ahighfee adhighfee highfee issue_amount maturity_years n_cumulative coupon revenue negotiated callable if fitch == 1 , a(year) cluster(issuer_name)
test aaahighfee + highfee = 0
test aauhighfee + highfee = 0
test aahighfee + highfee = 0
test aadhighfee + highfee = 0
test auhighfee + highfee = 0
test ahighfee + highfee = 0
test adhighfee + highfee = 0
	
/* Table A1 Panel A */
tabstat rdelta rating_fee_residual , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 21 , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 18 & rating_num <= 21 , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 15 & rating_num <= 18 , by(residual_five) s(mean sd n semean)

ttest rdelta if (residual_five == 1 | residual_five == 5) , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 21 , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 18 & rating_num <= 21 , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 15 & rating_num <= 17 , by(residual_five)

/* Table A1 Panel B */
tabstat rdelta rating_fee_residual , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 21 , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 18 & rating_num <= 21 , by(residual_five) s(mean sd n semean)
tabstat rdelta rating_fee_residual if rating_num > 15 & rating_num <= 18 , by(residual_five) s(mean sd n semean)

ttest rdelta if (residual_five == 1 | residual_five == 5) , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 21 , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 18 & rating_num <= 21 , by(residual_five)
ttest rdelta if (residual_five == 1 | residual_five == 5) & rating_num > 15 & rating_num <= 17 , by(residual_five)

/* Figure 1 Panel A Panel B Panel C */
scatter moodys_fee sp_fee , xtitle(Standard & Poor's fee) ytitle(Moody's fee) ylabel(,nogrid) graphregion(color(white)) msymbol(smcircle) 
scatter moodys_fee fitch_fee , xtitle(Fitch fee) ytitle(Moody's fee) ylabel(,nogrid) graphregion(color(white)) msymbol(smcircle)
scatter sp_fee fitch_fee , xtitle(Fitch fee) ytitle(Standard & Poor's fee) ylabel(,nogrid) graphregion(color(white)) msymbol(smcircle)

/* Figure 2 Panel A Panel B Panel C */
by year: sum issue_insured ambac mbia

/* Figure 3 Panel A Panel B Panel C */
twoway (scatter moodys_fee moodys , msymbol(smcircle)) (lfit moodys_fee moodys) , xtitle(Moody's credit rating) ytitle(Moody's fee) legend(off) ylabel(,nogrid) graphregion(color(white))  
twoway (scatter sp_fee sp , msymbol(smcircle)) (lfit sp_fee sp) , xtitle(Standard & Poor's credit rating) ytitle(Standard & Poor's fee) legend(off) ylabel(,nogrid) graphregion(color(white))
twoway (scatter fitch_fee fitch , msymbol(smcircle)) (lfit fitch_fee fitch) , xtitle(Fitch credit rating) ytitle(Fitch fee) legend(off) ylabel(,nogrid) graphregion(color(white))
pwcorr moodys_fee moodys sp_fee sp fitch_fee fitch , sig

/* Figure 4 */
twoway (scatter moodyssp_num moodyssp_fee , msymbol(smcircle)) (lfit moodyssp_num moodyssp_fee) , xtitle(Moody's fee - S&P fee) ytitle(Moody's rating - S&P rating) legend(off) ylabel(,nogrid) graphregion(color(white))
twoway (scatter spfitch_num spfitch_fee , msymbol(smcircle)) (lfit spfitch_num spfitch_fee) , xtitle(S&P fee - Fitch fee) ytitle(S&P rating - Fitch rating) legend(off) ylabel(,nogrid) graphregion(color(white))
twoway (scatter moodysfitch_num moodysfitch_fee , msymbol(smcircle)) (lfit moodysfitch_num moodysfitch_fee) , xtitle(Moody's fee - Fitch fee) ytitle(Moody's rating - Fitch rating) legend(off) ylabel(,nogrid) graphregion(color(white))

pwcorr moodyssp_num moodyssp_fee , sig
pwcorr spfitch_num spfitch_fee , sig
pwcorr moodysfitch_num moodysfitch_fee , sig 

/* Figure 5 */
pwcorr moodys_numavg moodys_feeresidavg , sig obs
pwcorr sp_numavg sp_feeresidavg , sig obs
pwcorr fitch_numavg fitch_feeresidavg , sig obs 

twoway (scatter moodys_numavg moodys_feeresidavg , msymbol(smcircle)) (lfit moodys_numavg moodys_feeresidavg) , ytitle(Moody's rating difference) xtitle(Moody's Residual fee difference) legend(off) legend(off) ylabel(,nogrid) graphregion(color(white))
twoway (scatter sp_numavg sp_feeresidavg , msymbol(smcircle)) (lfit sp_numavg sp_feeresidavg) , ytitle(S&P rating difference) xtitle(S&P Residual fee difference) legend(off) legend(off) ylabel(,nogrid) graphregion(color(white)) 
twoway (scatter fitch_numavg fitch_feeresidavg , msymbol(smcircle)) (lfit fitch_numavg fitch_feeresid) , ytitle(Fitch rating difference) xtitle(Fitch Residual fee difference) legend(off) legend(off) ylabel(,nogrid) graphregion(color(white)) 

/* Figure 7 */
local i = 2005
while `i' <= 2020 {
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if year == `i' , a(issue_fe) cluster(issue_fe)
local i = `i' + 1
}
reghdfe rating_num sdrating_fee_residual moodys moodyspost051007 fitch fitchpost041005 if year <= 2008 , a(issue_fe) cluster(issue_fe)

/* Figure 8 */
local i = 2005
while `i' <= 2020 {
areg rating_num sdrating_fee_residual if moodys == 1 & ((year == `i') | (year == `i' + 1) | (year == `i' + 2)), a(issuer_fe)
local i = `i' + 1
}

local i = 2005
while `i' <= 2020 {
areg rating_num sdrating_fee_residual if moodys == 0 & fitch == 0 & ((year == `i') | (year == `i' + 1) | (year == `i' + 2)) , a(issuer_fe)
local i = `i' + 1
}

local i = 2005
while `i' <= 2020 {
areg rating_num sdrating_fee_residual if fitch == 1 & ((year == `i') | (year == `i' + 1) | (year == `i' + 2)) , a(issuer_fe)
local i = `i' + 1
}

/* Figure A2 */
tabstat bond_insurance_fee , by(rating_num) s(p25 p50 p75)

